package com.example.myapp;

import com.example.myapp.utils.utils;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class view_text extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_view_text);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


//        获取对象
        TextView t = findViewById(R.id.t);
        t.setBackgroundColor(Color.RED);
//        设置文本
        t.setText("你好世界");
        t.setTextColor(Color.WHITE);

//        设置文本大小
//        t.setTextSize(50);



        TextView text = findViewById(R.id.text);
        text.setTextSize(20);
        text.setText("java设置宽度");
        text.setBackgroundResource(R.color.red);
        ViewGroup.LayoutParams params = text.getLayoutParams();
        params.width = utils.pidToPx(this, 100);
        text.setLayoutParams(params);


    }
}